var repayDetailData,repayTotal=0,api=frameElement.api,W=api.opener,_param_id = api.data['id'],repaymentId = api.data['repaymentId'],loanId = api.data['loanId'],repayRealDate = api.data['repayRealDate'],repayType = api.data['repayType'],deadlineNumber = api.data['deadlineNumber']; // 通过数据共享的方法获取调用页面文本框中的值;
$(document).ready(function() {
	var array = new Array;
	array.push({name:'beanProxy[enable]',value:0});
	array.push({name:'beanProxy[loanId]',value:loanId});
	array.push({name:'beanProxy[repaymentId]',value:repaymentId});
	array.push({name:'isNonPage',value:1});
	initLastEnterprise(array,null,null);
});

var initOther = function(){
	
	//设置提前应收值
	$.ajax({
		url:'sys/LoanExt/computerRepaymentDetail',
		data:{'repaymentId':repaymentId,'repayType':'3','id':_param_id,'repayRealDate':repayRealDate},
		type:'post',
		dataType:'json',
		async:false,
		success:function(result){
			if(typeof(result)!='undefined'){
				_set_lable_text ('#currentRepayDetailSum span ','name','',false,result.data);
			}
		},
		complete:function(){
		}
	});
//	//查询详情
//	var aoData = {repayRealDate:repayRealDate,repayType:repayType,id:_param_id,repaymentId:repaymentId};
//	$.ajax( {
//		type: "POST", 
//		url: 'sys/LoanExt/computerRepaymentDetailThis', 
//		cache : false,
//		async:false,
//		dataType : "json",
//		data : aoData, 
//		success: function(resp) {
//			if(resp && resp.state == 200){
//				var data = resp.data;
//					//重新计算应还总额
//				_set_lable_text('#currentRepayDetail span ','name','',false,data);
//				return false;
//			}
//		}
//	});

};



var initLastEnterprise  = function(array,planTotal,planCapital){
	if(typeof(planTotal)=='undefined'){
		planTotal=function (data, display, row) {
			return data;
		};
	};
	if(typeof(planCapital)=='undefined'){
		planCapital=function (data, display, row) {
			return data;
		};
	};
	
	$('#lastEnterprise').dataTable({
		"bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示
		"bServerSide" : true, //是否启动服务器端数据导入
		"bStateSave" : false, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态
		"bJQueryUI" : true, //是否使用 jQury的UI theme
		//"aLengthMenu" : [5, 10, 15], //更改显示记录数选项
		"iDisplayLength" : 10, //默认显示的记录数
		"bAutoWidth" : true, //是否自适应宽度 update
		"bScrollCollapse" : false, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变
		"bPaginate" : false, //是否显示（应用）分页器
		"bInfo" : false, //是否显示页脚信息，DataTables插件左下角显示记录数
		"sPaginationType" : "full_numbers", //详细分页组，可以支持直接跳转到某页
		"bSort" : true, //是否启动各个字段的排序功能
		"aaSorting" : [[0, "ASC"]], //默认的排序方式，第3列，升序排列
		"bFilter" : false, //是否启动过滤、搜索功能
		"sPaginationType": "full_numbers",
		"sScrollX": '100%',
		'destroy':true,
		"sScrollXInner": 1350,
		"sAjaxSource":"sys/LoanRepaymentDetail/list",
		"fnServerData": function( sSource, aoData, fnCallback ) {
			$.merge(aoData,array);//合并
			$.unique(aoData);//去重
			$.ajax( {
				type: "POST", 
				url: sSource, 
				cache : false,
				dataType : "json",
				data : aoData, 
				success: function(resp) {
					if(resp && resp.state == 200){
						fnCallback(resp.datagrid);
						return false;
					}
					fnCallback(null);
				}
			});
		},  //自定义数据获取函数
		"aoColumns" : [ {
			"mDataProp" : "deadlineNumber",
			"sTitle" : "期数",
			"sDefaultContent" : "",
			"sClass" : "center",
			"bSortable": false
		},{
			"mDataProp" : "planCapital",
			"sTitle" : "本金",
			"sDefaultContent" : "",
			"sClass" : "center",
			"bSortable": false,
			"mRender":planCapital
		},{
			"mDataProp" : "planInterest",
			"sTitle" : "利息",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "planHandingFee",
			"sTitle" : "手续费",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		},{
			"mDataProp" : "planInspectFee",
			"sTitle" : "调查费",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		},{
			"mDataProp" : "planManageFee",
			"sTitle" : "管理费",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		},{
			"mDataProp" : "planOverdueFee",
			"sTitle" : "滞纳金",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		},{
			"mDataProp" : "planBreachFee",
			"sTitle" : "违约金",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		},{
			"mDataProp" : "planCollectionFee",
			"sTitle" : "催收费",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		},{
			"mDataProp" : "planLegalFee",
			"sTitle" : "法诉费",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		},{
			"mDataProp" : "planTotal",
			"sTitle" : "总计",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender":planTotal
		},{
			"mDataProp" : "repayTotal",
			"sTitle" : "收款金额",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		},{
			"mDataProp" : "overdueDays",
			"sTitle" : "预期天数",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		},{
			"mDataProp" : "overdueStatus",
			"sTitle" : "预期状态",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender":function(tdata, display, row){
				if(_is_not_empty(tdata)){
					if(1 == tdata){
						return '正常';
					}else{
						return '逾期';
					}
				}
					return '异常状态!';
			}
		}
		],
		"oLanguage": {
			"sUrl":top.basePath+"static_resources/language/lang-cn.txt" //这个是国际化，也就是汉化的各种文字数据源，写对url就行了
		},
		"footerCallback": function (tfoot, row, data, start, end, display ) {
			//初始化其他
			initOther();

		}
	});

};
